class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int sz = nums.size();
        if(sz == 0)
            return 0;
            
        int maxsofar = INT_MIN;
        int sum = 0;
        for(int i = 0; i < sz; i++)
        {
            sum += nums[i];
            if(sum > maxsofar)
                maxsofar = sum;
            if(sum < 0)
                sum = 0;
        }
        
        return maxsofar;
    }
};